from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-04-04 14:10:24.918035
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 04, Apr, 2021
Time: 14:10:29
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.3370
Nobs: 251.000 HQIC: -48.0924
Log likelihood: 2984.06 FPE: 7.81555e-22
AIC: -48.6011 Det(Omega_mle): 5.49868e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.446042 0.126967 3.513 0.000
L1.Burgenland 0.072335 0.062685 1.154 0.249
L1.Kärnten -0.218771 0.054202 -4.036 0.000
L1.Niederösterreich 0.075187 0.139444 0.539 0.590
L1.Oberösterreich 0.223393 0.129257 1.728 0.084
L1.Salzburg 0.266141 0.070350 3.783 0.000
L1.Steiermark 0.141674 0.090202 1.571 0.116
L1.Tirol 0.114722 0.061637 1.861 0.063
L1.Vorarlberg -0.030561 0.057047 -0.536 0.592
L1.Wien -0.077169 0.116910 -0.660 0.509
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.483989 0.151306 3.199 0.001
L1.Burgenland 0.005334 0.074702 0.071 0.943
L1.Kärnten 0.336235 0.064592 5.206 0.000
L1.Niederösterreich 0.106249 0.166174 0.639 0.523
L1.Oberösterreich -0.075540 0.154034 -0.490 0.624
L1.Salzburg 0.211791 0.083835 2.526 0.012
L1.Steiermark 0.115288 0.107493 1.073 0.283
L1.Tirol 0.137468 0.073452 1.872 0.061
L1.Vorarlberg 0.156907 0.067982 2.308 0.021
L1.Wien -0.464825 0.139320 -3.336 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.301550 0.062104 4.856 0.000
L1.Burgenland 0.093270 0.030662 3.042 0.002
L1.Kärnten -0.015253 0.026512 -0.575 0.565
L1.Niederösterreich 0.041720 0.068207 0.612 0.541
L1.Oberösterreich 0.281541 0.063224 4.453 0.000
L1.Salzburg 0.017821 0.034411 0.518 0.605
L1.Steiermark 0.027589 0.044121 0.625 0.532
L1.Tirol 0.064703 0.030149 2.146 0.032
L1.Vorarlberg 0.084563 0.027904 3.031 0.002
L1.Wien 0.108520 0.057185 1.898 0.058
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.214630 0.063277 3.392 0.001
L1.Burgenland 0.021811 0.031241 0.698 0.485
L1.Kärnten 0.007718 0.027013 0.286 0.775
L1.Niederösterreich 0.047758 0.069495 0.687 0.492
L1.Oberösterreich 0.403609 0.064418 6.265 0.000
L1.Salzburg 0.082545 0.035060 2.354 0.019
L1.Steiermark 0.133116 0.044954 2.961 0.003
L1.Tirol 0.049596 0.030718 1.615 0.106
L1.Vorarlberg 0.082674 0.028431 2.908 0.004
L1.Wien -0.043490 0.058264 -0.746 0.455
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.511547 0.123757 4.133 0.000
L1.Burgenland 0.083394 0.061100 1.365 0.172
L1.Kärnten 0.011366 0.052831 0.215 0.830
L1.Niederösterreich -0.026953 0.135918 -0.198 0.843
L1.Oberösterreich 0.130989 0.125988 1.040 0.298
L1.Salzburg 0.057262 0.068571 0.835 0.404
L1.Steiermark 0.093398 0.087921 1.062 0.288
L1.Tirol 0.210792 0.060079 3.509 0.000
L1.Vorarlberg 0.029826 0.055604 0.536 0.592
L1.Wien -0.092859 0.113953 -0.815 0.415
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.190899 0.096956 1.969 0.049
L1.Burgenland -0.019989 0.047869 -0.418 0.676
L1.Kärnten -0.013227 0.041390 -0.320 0.749
L1.Niederösterreich -0.024969 0.106484 -0.234 0.815
L1.Oberösterreich 0.399357 0.098705 4.046 0.000
L1.Salzburg 0.013646 0.053721 0.254 0.799
L1.Steiermark 0.006082 0.068881 0.088 0.930
L1.Tirol 0.152640 0.047068 3.243 0.001
L1.Vorarlberg 0.058834 0.043563 1.351 0.177
L1.Wien 0.242488 0.089276 2.716 0.007
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.246739 0.119389 2.067 0.039
L1.Burgenland 0.021370 0.058944 0.363 0.717
L1.Kärnten -0.065050 0.050967 -1.276 0.202
L1.Niederösterreich -0.060717 0.131121 -0.463 0.643
L1.Oberösterreich 0.020590 0.121542 0.169 0.865
L1.Salzburg 0.075568 0.066151 1.142 0.253
L1.Steiermark 0.333021 0.084818 3.926 0.000
L1.Tirol 0.458970 0.057958 7.919 0.000
L1.Vorarlberg 0.149248 0.053642 2.782 0.005
L1.Wien -0.174810 0.109932 -1.590 0.112
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.140342 0.140756 0.997 0.319
L1.Burgenland 0.049903 0.069493 0.718 0.473
L1.Kärnten -0.070545 0.060088 -1.174 0.240
L1.Niederösterreich 0.193785 0.154587 1.254 0.210
L1.Oberösterreich -0.005338 0.143294 -0.037 0.970
L1.Salzburg 0.202536 0.077989 2.597 0.009
L1.Steiermark 0.117301 0.099998 1.173 0.241
L1.Tirol 0.056049 0.068331 0.820 0.412
L1.Vorarlberg 0.100438 0.063242 1.588 0.112
L1.Wien 0.219687 0.129606 1.695 0.090
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.590460 0.076580 7.710 0.000
L1.Burgenland -0.040325 0.037808 -1.067 0.286
L1.Kärnten -0.025111 0.032691 -0.768 0.442
L1.Niederösterreich 0.016334 0.084105 0.194 0.846
L1.Oberösterreich 0.327526 0.077961 4.201 0.000
L1.Salzburg 0.019441 0.042431 0.458 0.647
L1.Steiermark -0.033410 0.054405 -0.614 0.539
L1.Tirol 0.087567 0.037176 2.355 0.019
L1.Vorarlberg 0.111071 0.034408 3.228 0.001
L1.Wien -0.045211 0.070514 -0.641 0.521
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.138708 0.039358 0.162650 0.216411 0.055443 0.078596 -0.004683 0.149959
Kärnten 0.138708 1.000000 0.020041 0.204064 0.178591 -0.066251 0.159881 0.022895 0.307090
Niederösterreich 0.039358 0.020041 1.000000 0.243061 0.069066 0.302468 0.134276 0.030458 0.300727
Oberösterreich 0.162650 0.204064 0.243061 1.000000 0.299377 0.271364 0.090056 0.059698 0.136406
Salzburg 0.216411 0.178591 0.069066 0.299377 1.000000 0.158735 0.047790 0.089116 -0.000058
Steiermark 0.055443 -0.066251 0.302468 0.271364 0.158735 1.000000 0.103538 0.093535 -0.120962
Tirol 0.078596 0.159881 0.134276 0.090056 0.047790 0.103538 1.000000 0.162680 0.143843
Vorarlberg -0.004683 0.022895 0.030458 0.059698 0.089116 0.093535 0.162680 1.000000 0.000947
Wien 0.149959 0.307090 0.300727 0.136406 -0.000058 -0.120962 0.143843 0.000947 1.000000